/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.krazevina.luatgiaothong;

import java.util.Vector;

/**
 *
 * @author XXX
 */
public class Song {
    public int ID;
    public String name,rawname,lyric,rawlyric,artist,rawartist;
    public int vol;
    public Song(){}
    public Song(int id,String name,String rname,String lyric,String rlyric,int vol){
        this.ID = id;
        this.name = name;
        this.rawlyric = rlyric;
        this.rawname = rname;
        this.vol = vol;
    }
    public Song(String line){
        String[]lines = split(line,"\"");
        try{
            ID = Integer.parseInt(lines[0].substring(0, lines[0].length()-1));
            name = lines[1];
            lyric = lines[3];
            rawname = lines[5];
            rawlyric = lines[7];
            vol = Integer.parseInt(lines[8].substring(1,lines[8].length()-1));
            artist = lines[9];
            rawartist = lines[11];
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    
    /**
     * @param s : string to find
     * @return : 0 to 10
     * 
     */
    
    public int isName(String s, boolean op){
        if(op){
            if(rawname.indexOf(s)>=0&&vol<100)return 1;
        }else
            if(name.indexOf(s)>=0&&vol>=100)return 1;
        return 1000;
    }
    public int isArtist(String s, boolean op){
        if(op){
            if(artist.indexOf(s)>=0&&vol<100)return 1;
        }
        else
            if(artist.indexOf(s)>=0&&vol>=100)return 1;

        return 1000;
    }
    public int isLyrics(String s){
        if(rawlyric.indexOf(s)>=0&&vol<100)return 1;
        return 1000;
    }
    
    public int isCode(String s,boolean op){
        if(op){
            if((""+ID).indexOf(s)>=0&&vol<100)return 1;
        }else{
            if((""+ID).indexOf(s)>=0&&vol>=100)return 1;
        }
        return 1000;
    }
    
    private String[] split(String original,String separator) {
        Vector nodes = new Vector();
        int index = original.indexOf(separator);
        while(index>=0) {
            nodes.addElement( original.substring(0, index) );
            original = original.substring(index+separator.length());
            index = original.indexOf(separator);
        }
        nodes.addElement( original );
        String[] result = new String[ nodes.size() ];
        if( nodes.size()>0 ) {
            for(int loop=0; loop<nodes.size(); loop++)
                result[loop] = (String)nodes.elementAt(loop);
        }
        return result;
    }
    public void out(){
        System.out.println(""+ID+":"+rawname);
    }
}
